#ifndef VISIBILITY_H
#define VISIBILITY_H
#include <QtSerialPort/QSerialPort>
#include <QDateTime>
#include <QString>


//extern const int VISIBILITY_PROTOCOLALL_LENGTH;

#define VISIBILITY_PROTOCOLALL_LENGTH 97

class VisibilityProtocolAll{
public:
    int one_minute_visibility;
    int ten_minute_visibility;
    int TheIntensityOfEmittedEnergy;
    int TheIntensityOfReceivedEnergy;
    double RatedPower;
    double sendPollution;
    double receivedPollution;
    QString deviceState;
    QString device_code;
    QDateTime date_time;
};
//能见度仪解析类
class Visibility :public QObject
{
    Q_OBJECT
public:

    QSerialPort* m_port;
    QByteArray m_readBuffer;

    ~Visibility() {};
    static Visibility* getInstance();
    bool openDevice(QString portName);
    void closeDevice();

    signals:
    //VisibilityProtocol类中保存从协议中解析出来的数据。持有Visibility对象的界面在初始化时，将此信号和一个更新界面的函数进行连接即可
    void updateView(const VisibilityProtocolAll&);
    //解析命令的信号，QByteArray为协议格式的数据，在构造函数时connect信号和一个解析协议的lambda函数，函数完成解析后发出updateView信号
    void protocol(QByteArray);



private:
    static Visibility* instance;

    Visibility(QObject* parent = nullptr);
    QString checkDevState(QString DevStaStr);


};

#endif // VISIBILITY_H
